package dfs;

import java.util.LinkedList;

/**
 * @author hht
 * @ClassName Solution
 * @Description TODO
 * @Date 2019/7/4 21:53
 * @VERSION 1.0
 */
public class Solution {
    public static void main(String[] args) {
        TreeNode root = new Solution().new TreeNode(1);
        TreeNode c11 = new Solution().new TreeNode(2);
        TreeNode c12 = new Solution().new TreeNode(3);
        TreeNode c112 = new Solution().new TreeNode(5);
        root.addLeft(c11);
        root.addRight(c12);
        c11.addLeft(c112);
        depthOrderTraverse(root);
    }
    public static void depthOrderTraverse(TreeNode root) {
        if (root == null) {
            return;
        }
        LinkedList<TreeNode> stack = new LinkedList<>();
        stack.push(root);
        while (!stack.isEmpty()) {
            TreeNode node = stack.pop();
            System.out.print(node.val + "  ");
            if (node.right != null) {
                stack.push(node.right);
            }
            if (node.left != null) {
                stack.push(node.left);
            }
        }
    }
    class TreeNode{
        TreeNode right;
        TreeNode left;
        Object val;
        public  TreeNode(Object val){
            this.val = val;
        }
        public TreeNode addLeft(TreeNode left){
            this.left = left;
            return left;
        }
        public TreeNode addRight(TreeNode right){
            this.right = right;
            return right;
        }
    }
}
